// secondary_page/details_page/details_page.js
import Notify from '@vant/weapp/notify/notify';
import Dialog from '@vant/weapp/dialog/dialog';
const audioCtx = wx.createWebAudioContext()
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },
    MyMsg(){
      console.log(111);
      Notify({ type: 'danger', message: 'orangqiqi is dangergirl' });
      // Dialog.confirm({
      //   title: '标题',
      //   message: 'hahaha',
      // })
      //   .then(() => {
      //     // on confirm
      //   })
      //   .catch(() => {
      //     // on cancel
      //   });
    },
    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

        this.loadAudio('https://m804.music.126.net/20250328170851/ead2f5098544656adccb6b19815498c3/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/56847848171/7e30/0e9d/fddc/b2d7df4e44600c138d97f83052a26002.m4a?vuutv=x8ZlTx8PvAw8bO0lm8JngllySGE3jD0eoAnnHygcYTEww1saX/LZEE8oq8qCG8jK7X2SsGTTppD8qF4HQHOTBPIH71MzzKt9CtACaRZSg4c=&authSecret=00000195dbebfe94070b0a3b188073d5').then(buffer => {
          let source = audioCtx.createBufferSource()
          source.buffer = buffer
          source.connect(audioCtx.destination)
          source.start()
        }).catch(() => {
          console.log('fail')
        })
    },
  loadAudio(url){
      return new Promise((resolve) => {
        wx.request({
          url,
          responseType: 'arraybuffer',
          success: res => {
            console.log('res.data', res.data)
            audioCtx.decodeAudioData(res.data, buffer => {
              resolve(buffer)
            }, err => {
              console.error('decodeAudioData fail', err)
              reject()
            })
          },
          fail: res => {
            console.error('request fail', res)
            reject()
          }
        })
      })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})